<?php
	/*
	file ini digunakan untuk mengontrol login apakah user telah sesuai prosedur masuk aplikasi
	*/
class c_files extends CI_Controller {

	function __construct(){
		parent::__construct();
		session_start();
		$this->load->model('m_files');
		if(!isset($_SESSION[SESSION_USERID])){
			redirect(base_url());
		}

	}//end Login

	function get_action(){
		$task = isset($_POST['task']) ? @$_POST['task'] : $_GET['task'];
		switch($task){
			case "list":
				$this->files_list();
			break;
			case "create":
				$this->files_create();
			break;
			case "update":
				$this->files_update();
			break;
			case "delete":
				$this->files_delete();
			break;
			case "search":
				$this->files_search();
			break;
			default:
				echo "{ failure : true }";
			break;
		}
	}

	function index(){
		$data["title"]="file";
		$data["content"]=$this->load->view('admin/v_files_list',$data,TRUE);
		$this->load->view('admin/v_template',$data);
	}

	function file_load(){
		$this->load->view('admin/v_files_list');
	}

	function file_addedit(){
		$data = array();
		$id = $this->uri->segment(3);
		if($id != false){
			$data['dataDetail'] = $this->m_files->getDetail($id);
		}
		$this->load->view('admin/v_files_post', $data);
	}

	function files_list(){
		$query = $this->input->get('query');
		$pagenum = $_GET['pagenum'];
		$pagesize = $_GET['pagesize'];
		$start = $pagenum * $pagesize;
		$end = $start + $pagesize;

		$result=$this->m_files->files_list($query, $start, $end);
		echo $result;
	}

	function file_save(){
		$id = $this->input->post('id');
		$kat_id = $this->input->post('kat_id');
		$kat_id = is_numeric($kat_id) ? $kat_id : 0;
		$judul = $this->input->post('judul');
		$tanggal = $this->input->post('tanggal');
		$tag = $this->input->post('tag');
		$keterangan = $this->input->post('keterangan');
		$publish = $this->input->post('publish');
		$file_attach = $this->input->post('file_attach');
		$task = $this->input->post('task');
		$data = array(
			'judul'=>$judul,
			'tanggal'=>$tanggal,
			'tag'=>$tag,
			'keterangan'=>$keterangan,
			'publish'=>$publish,
			'file_attach'=>$file_attach
		);
		if($kat_id != 0){
			$data["kat_id"]=$kat_id;
		}
		$params = array(
			'id'=>$id,
			'data'=>$data,
			'task'=>$task
		);
		$result = $this->m_files->file_save($params);
		echo $result;
	}



	function file_delete(){
		$id = $this->input->post('id');
		$id = is_numeric($id) ? $id : $id;
		$result = $this->m_files->file_delete($id);
		echo $result;
	}


	function files_search(){

	}

	function files_update(){

	}

	function files_create(){

	}

}
?>
